Adding kv-cache invalidation when generation hits short factor threshold#4117
Open
AlexanderKalistratov wants to merge 7 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds LongRoPE “short-factor → long-factor” transition handling for the stateful LLM pipeline by detecting the model’s LongRoPE switch threshold from config.json and forcing KV-cache invalidation / reprefill when crossing that boundary (including a mid-generation split for SDPA).
Changes:
- Detect LongRoPE usage + threshold from
config.jsonand store it inStatefulLLMPipeline. - Force a one-off full-history resend + cache reset when a chat turn crosses the threshold; add a streamer-based mid-generation stop-and-rerun path.
- Ensure LongRoPE threshold detection is invoked in stateful pipeline construction paths.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/cpp/src/lm_encoding.cpp |
Minor formatting/whitespace updates. |
src/cpp/src/llm/pipeline.cpp |
Calls StatefulLLMPipeline::set_longrope_threshold(models_path) after construction to initialize LongRoPE behavior. |
src/cpp/src/llm/pipeline_stateful.hpp |
Adds LongRoPE threshold state and “one-shot” reprefill flag declarations. |
src/cpp/src/llm/pipeline_stateful.cpp |
Implements LongRoPE threshold detection and adds cache-reset + rerun logic when the boundary is reached. |
AsyaPronina
approved these changes
Jul 9, 2026
AsyaPronina
reviewed
Jul 9, 2026
4360de1 to
726a031
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add support for short-factor to long-factor RoPe transition via cache invalidation for SDPA backend.
This is a functional support of the feature as cache-invalidation has performance impact.
Tested on CPU and NPU plugins.
Currently this functionality is enabled for NPU only, but can be extended to other plugins.
EISW-223126
Checklist: